package com.cloud.shopping.search.controller;

import com.cloud.shopping.search.model.SkuEs;
import com.cloud.shopping.search.service.SkuSearchService;
import com.cloud.shopping.tool.RespResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author John.zhang
 * @version Id: SkuSearchController, v 1.0 2020/12/31 11:17 ZhiYong Exp $
 */

@Api(tags = "商品搜索模块")
@RestController
@RequestMapping(value = "/search")
public class SkuSearchController {

    @Resource
    private SkuSearchService skuSearchService;

    /**
     * 商品搜索
     *
     * @param searchMap searchMap
     * @return RespResult
     */

    @ApiOperation("商品搜索")
    @ApiImplicitParam(name = "searchMap", value = "搜索关键词Map")
    @GetMapping
    public RespResult<Map<String, Object>> search(@RequestParam(required = false) Map<String, Object> searchMap) {
        Map<String, Object> resultMap = skuSearchService.search(searchMap);
        return RespResult.ok(resultMap);
    }

    /**
     * 增加索引
     *
     * @param skuEs skuEs
     * @return RespResult
     */
    @ApiOperation("增加商品索引")
    @ApiImplicitParam(name = "skuEs", value = "商品信息", required = true)
    @PostMapping(value = "/add")
    public RespResult add(@RequestBody SkuEs skuEs) {
        skuSearchService.add(skuEs);
        return RespResult.ok();
    }

    /**
     * 删除索引
     *
     * @param id id
     * @return RespResult
     */
    @ApiOperation("删除商品索引")
    @ApiImplicitParam(name = "id", value = "索引", required = true)
    @DeleteMapping(value = "/delete/{id}")
    public RespResult delete(@PathVariable(value = "id") String id) {
        skuSearchService.delete(id);
        return RespResult.ok();
    }

}
